]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dnd: Set dnd actor size instead of scaling it when reparenting
authorSebastian Keller <skeller@gnome.org>
Mon, 15 Feb 2021 23:54:37 +0000 (00:54 +0100)
committerSebastian Keller <skeller@gnome.org>
Tue, 16 Feb 2021 00:07:23 +0000 (01:07 +0100)
Previously the actor could end up using its natural size and then get
scaled down to its allocation before reparenting. This however could
affect the layout of the widget due to the larger size. To ensure the
widget looks the same after reparenting set the size to its original
size.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3717

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1680>

js/ui/dnd.js

index ad92d7ee77a43cf557b0543805c8d721e04179fd..6b4a9838233e3ea5971d35eae471c5328598d5cf 100644 (file)
@@ -382,24 +382,18 @@ var _Draggable = class _Draggable {
             this._dragActorHadFixedPos = this._dragActor.fixed_position_set;
             this._dragOrigX = this._dragActor.allocation.x1;
             this._dragOrigY = this._dragActor.allocation.y1;
+            this._dragActorHadNatWidth = this._dragActor.natural_width_set;
+            this._dragActorHadNatHeight = this._dragActor.natural_height_set;
             this._dragOrigWidth = this._dragActor.allocation.get_width();
             this._dragOrigHeight = this._dragActor.allocation.get_height();
             this._dragOrigScale = this._dragActor.scale_x;
 
-            // When the actor gets reparented to the uiGroup, it will be
-            // allocated its preferred size, so use that size instead of the
-            // current allocation size.
-            const [, newAllocatedWidth] = this._dragActor.get_preferred_width(-1);
-            const [, newAllocatedHeight] = this._dragActor.get_preferred_height(-1);
+            // Ensure actors with an allocation smaller than their natural size
+            // retain their size
+            this._dragActor.set_size(...this._dragActor.allocation.get_size());
 
             const transformedExtents = this._dragActor.get_transformed_extents();
 
-            // Set the actor's scale such that it will keep the same
-            // transformed size when it's reparented to the uiGroup
-            this._dragActor.set_scale(
-                transformedExtents.get_width() / newAllocatedWidth,
-                transformedExtents.get_height() / newAllocatedHeight);
-
             this._dragOffsetX = transformedExtents.origin.x - this._dragStartX;
             this._dragOffsetY = transformedExtents.origin.y - this._dragStartY;
 
@@ -757,6 +751,10 @@ var _Draggable = class _Draggable {
                 dragActor.set_position(this._dragOrigX, this._dragOrigY);
             else
                 dragActor.fixed_position_set = false;
+            if (this._dragActorHadNatWidth)
+                this._dragActor.set_width(-1);
+            if (this._dragActorHadNatHeight)
+                this._dragActor.set_height(-1);
         } else {
             dragActor.destroy();
         }